﻿
Imports osi.interface.storage

Public Class wrappered_accessor
    Inherits accessor_wrapper(Of accessor_t)
    Implements accessor_t

    Protected Sub New(ByVal a As accessor_t)
        MyBase.New(a)
    End Sub

    Public Function [erase](ByVal key As String) As eventComb _
                           Implements accessor_t.erase
        debug_info(New lazyStrCat("erase ", key))
        Return a.erase(key)
    End Function

    Public Function read(ByVal key As String, ByVal result As pointer(Of bytes)) As eventComb _
                        Implements accessor_t.read
        debug_info(New lazyStrCat("read ", key))
        Return a.read(key, result)
    End Function

    Public Function write(ByVal key As String, ByVal value As bytes) As eventComb _
                         Implements accessor_t.write
        debug_info(New lazyStrCat("write ",
                                  key,
                                  " with ",
                                  If(value Is Nothing, "#EMPTY_INSTANCE#", value.size()),
                                  " bytes data"))
        Return a.write(key, value)
    End Function

    Public Function exist(ByVal key As String, ByVal result As pointer(Of Boolean)) As eventComb _
                         Implements accessor_t.exist
        debug_info(New lazyStrCat("find ", key))
        Return a.exist(key, result)
    End Function

    Public Function sizeof(ByVal key As String, ByVal result As pointer(Of UInt64)) As eventComb _
                          Implements accessor_t.sizeof
        debug_info(New lazyStrCat("sizeof ", key))
        Return a.sizeof(key, result)
    End Function

    Private Sub debug_info(ByVal msg As lazyStrCat)
        If debug() Then
            raiseError(msg)
        End If
    End Sub
End Class
